package com.atguigu.eduservice.controller.front;

import com.atguigu.common_uitls.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * zz: wzh
 * time 2022 10 04 19 24
 **/
@RequestMapping("eduservice/teacherfront")
@RestController
@CrossOrigin
public class teacherFrontController {
    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduCourseService eduCourseService;
    @PostMapping("getTeacherList/{page}/{limit}")
    public R getTeacherList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> eduTeacherPage = new Page(page, limit);
        Map<String,Object> map=eduTeacherService.getTeacherList(eduTeacherPage);
        return R.ok().data("map",map);
    }
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId) {
        //1根据讲师id查询讲师的基本id
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);
        //2根据讲师id查询所有课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", teacherId);
        List<EduCourse> courseList = eduCourseService.list(wrapper);
        return R.ok().data("teacher", eduTeacher).data("courseList", courseList);
    }

}
